package gov.nhso.prov.acc.core;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class DBConnection {
    private static DataSource ds = null;
	public static synchronized Connection getConnection() throws SQLException {
		Connection conn = null;
		try {
			if (ds == null) {
				Context envCtx = (Context) new InitialContext();
				ds = (DataSource) envCtx.lookup(ConfigBundle.getValue("JNDI_DATASOURCE"));
				envCtx.close();
			}
			conn = ds.getConnection();
			conn.setAutoCommit(false);
		} catch (NamingException e) {
			e.printStackTrace();
		}
		return conn;
	}

}
